import { Link } from 'react-router'
require("!style!css!../../css/myApp.css");
var Table = ReactUI.Table
var Filter = ReactUI.Filter
var Modal = ReactUI.Modal
export default class UserManager extends React.Component {
    render() {
        var dataHeader='{"header":{"business":"findAllUser","destSystem":"SOAPlat","sourceSystem":"SOAPlat","rootParam":"User"},';
        var dataBody='"body":'+'{}';
        var data = dataHeader+dataBody+"}";
        return (
            <div>

                <div className="bg-light lter b-b wrapper-md">
                    <h1 className="m-n font-thin h3">用户管理 </h1>
                </div>
                <div className="TablePanel">
                    <div className="toolbar clearfix">
                        <div className="float-left">
                            <Link to="/userManager/add" className="btn m-b-xs btn-sm btn-info btn-addon"><i className="fa fa-plus"></i>新增</Link>

                        </div>
                        <div className="float-right">
                            <Filter onFilter={(filters) => this.setState({ filters })}

                                    local={true}
                                    options={[{
                                        label: '用户名',
                                        name: 'username',
                                        ops: ['like', '=', 'startWidth'],
                                        startWidth: function (d, value) {
                                          return d.name.indexOf(value) === 0;
                                        }
                                      }, {
                                        label: '姓名',
                                        name: 'realName',
                                        ops: ['='],
                                        type: 'select',
                                        props: { data: ['Tokyo', 'Singapore', 'New York', 'London', 'San Francisco'] }
                                      }]} />

                        </div>
                    </div>
                    <Table
                        bordered="true"
                        striped = "true"
                        fetch={{
                                method: 'post',
                                url: 'user/add',
                                data:{ data: data },
                                then: (res) => {
                                  if (res.status=="OK") {

                                    return JSON.parse(res.rtnStr);
                                  } else {
                                    return new Error(res.message);
                                  }
                                }
                          }}

                        headers={[
                                    { name: 'username', sortAble: true, header: '用户名'},
                                    { name: 'realName', sortAble: true, header: '姓名' },
                                    { name: 'officePhone', sortAble: true, content: '{officePhone}', header: '联系电话' },
                                    { name: 'email', content: '{email}', header: '邮箱' },
                                    { name: 'update', width: 60,header:"修改",
                                        content: (d) => {
                                            var link = {pathname:"userManager/update/"+d.id};
                                            return (<Link to={link}>修改</Link>);
                                        }
                                    },
                                    { name: 'tools', width: 60,header:"删除",
                                        content: (d) => {
                                            return (<
                                            a onClick={() => { Modal.confirm('确定要删除' + d.username + '吗', () => {
                                                var dataHeader='{"header":{"business":"delUser","destSystem":"SOAPlat","sourceSystem":"SOAPlat","rootParam":"User"},';
                                                var dataBody='"body":'+'{id:'+d.id+'}';
                                                var data = dataHeader+dataBody+"}";
                                               $.ajax({
                                                type: 'POST',
                                                url:'user/add',
                                                data: "data="+data,
                                                dataType:'json',
                                                success: function(result){
                                                    Modal.alert(result.rtnStr);
                                                },
                                                error:function(e){
                                                    Modal.alert("操作出错!");

                                                }
                                            })
                                            }); }}>删除</a>);
                                        }
                                    }
                                ]}
                    />

                </div>




            </div>

        )
    }
}